{
    "cells": [
        {
            "cell_type": "code",
            "execution_count": null,
            "metadata": {},
            "outputs": [],
            "source": [
                "# This is due to the fact that we use asyncio.loop_until_complete in\n",
                "# the DiscordReader. Since the Jupyter kernel itself runs on\n",
                "# an event loop, we need to add some help with nesting\n",
                "!pip install nest_asyncio\n",
                "import nest_asyncio\n",
                "nest_asyncio.apply()"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "metadata": {},
            "outputs": [],
            "source": [
                "%env OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n",
                "from llama_index import GPTSimpleVectorIndex, GithubRepositoryReader\n",
                "from IPython.display import Markdown, display\n",
                "import os"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "metadata": {},
            "outputs": [],
            "source": [
                "%env GITHUB_TOKEN=github_pat_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n",
                "github_token = os.environ.get(\"GITHUB_TOKEN\")\n",
                "owner = \"jerryjliu\"\n",
                "repo = \"gpt_index\"\n",
                "branch = \"main\"\n",
                "\n",
                "documents = GithubRepositoryReader(\n",
                "    github_token=github_token,\n",
                "    owner=owner,\n",
                "    repo=repo,\n",
                "    use_parser=False,\n",
                "    verbose=False,\n",
                ").load_data(branch=branch)"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "metadata": {},
            "outputs": [],
            "source": [
                "index = GPTSimpleVectorIndex.from_documents(documents)\n",
                "index.save_to_disk(\"github_index.json\")"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "metadata": {},
            "outputs": [],
            "source": [
                "# import time\n",
                "# for document in documents:\n",
                "#     print(document.extra_info)\n",
                "#     time.sleep(.25) \n",
                "response = index.query(\"What is the difference between GPTSimpleVectorIndex and GPTListIndex?\", verbose=True)"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "metadata": {},
            "outputs": [],
            "source": [
                "display(Markdown(f\"<b>{response}</b>\"))"
            ]
        }
    ],
    "metadata": {
        "kernelspec": {
            "display_name": "gpt_index-github-reader",
            "language": "python",
            "name": "python3"
        },
        "language_info": {
            "codemirror_mode": {
                "name": "ipython",
                "version": 3
            },
            "file_extension": ".py",
            "mimetype": "text/x-python",
            "name": "python",
            "nbconvert_exporter": "python",
            "pygments_lexer": "ipython3",
            "version": "3.11.0"
        },
        "orig_nbformat": 4,
        "vscode": {
            "interpreter": {
                "hash": "5bc2ab08ee48b6366504a28e3231c27a37c154a347ee8ac6184b716eff7bdbcd"
            }
        }
    },
    "nbformat": 4,
    "nbformat_minor": 2
}